﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace Pavilion.DesignerTool
{
    public class LayerContainerViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private UndoRedoController undo = new UndoRedoController();
        public FrameData CurrentFrame { get; set; }
        public NotifiableCollection<TextureData> LayerCollection { get { return (CurrentFrame == null) ? null : CurrentFrame.TextureDataCollection; } }
        public UndoRedoController UndoRedoController { get; set; }

        public LayerContainerViewModel()
        {
            UndoRedoController = new UndoRedoController();
        }

        public void LoadFrame(FrameData frameData)
        {
            CurrentFrame = frameData;

            if (CurrentFrame != null)
                UndoRedoController = CurrentFrame.UndoRedoController;
            else
                UndoRedoController = null;

            OnPropertyChanged("CurrentFrame");
            OnPropertyChanged("LayerCollection");
            OnPropertyChanged("UndoRedoController");
        }

        public void AddLayer() { LayerCollection.Add(CurrentFrame.CreateNewTexture()); }
        public void InsertNewLayer(int index) { LayerCollection.Insert(index, CurrentFrame.CreateNewTexture()); }
        public void RemoveLayer(TextureData textureData) { LayerCollection.Remove(textureData); }

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
